package com.pe.cineplanet.proyectocine.repository.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.pe.cineplanet.proyectocine.domain.Reserva;
import com.pe.cineplanet.proyectocine.repository.ReservaRepository;

@Repository
public class ReservaRepositoryHibernate extends HibernateDaoSupport 
implements ReservaRepository {
	
	//constructor
	@Autowired
	public ReservaRepositoryHibernate(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	public List<Reserva> obtenerReservas() {
		return getHibernateTemplate().find("from Reserva");   
	}

	public Reserva obtenerReserva(int nro_Reserva) {
		return (Reserva) getSession().createQuery("from Reserva u where u.nro_Reserva=?").setInteger(0, nro_Reserva).uniqueResult();
	}

	public void grabarReserva(Reserva obj) {
		getHibernateTemplate().saveOrUpdate(obj);
		
	}

	public void removerReserva(int nro_Reserva) {
		Reserva obj = obtenerReserva(nro_Reserva);
		getHibernateTemplate().delete(obj);
		
	}

}
